using System.Collections.Generic;
using Newtonsoft.Json;

namespace BuildWheel
{
    [System.Serializable]
    public class Folders : FileInfo
    {
        public List<Folders> childFolders = new List<Folders>();
        private List<string> childls = new List<string>();
        public List<File> files = new List<File>();

        public File AddFile(string strName, ResData data)
        {
            var file = new File(strName,data);
            files.Add(file);
            file.parent = this;
            return file;
        }

        public void AddChild(string str, int _layer)
        {
            if (!childls.Contains(str))
            {
                var f = new Folders();
                f.n = str;
                f.nameToLow = str.ToLower();
                f.layer = _layer;
                childFolders.Add(f);
                childls.Add(str);
                f.parent = this;
            }
        }

        public bool TryFind(int _layer, string _name, out Folders folders)
        {
            if (layer == _layer)
            {
                if (n == _name)
                {
                    folders = this;
                    return true;
                }
            }
            else
            {
                foreach (var childs in childFolders)
                {
                    if (childs.TryFind(_layer, _name, out folders))
                    {
                        return true;
                    }
                }
            }

            folders = null;
            return false;
        }
    }
}